﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Nova_MOD;
using Nova_BLL;
using Nova_DAL;
using System.Data.Common;
//xgw 
public partial class Login : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    DbHelper dbHelper = new DbHelper();
    DbCommand cmd = null;

    int i = 0;

    protected void Page_Load(object sender, EventArgs e)
    {


    }

    protected void ibtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        Nova_MOD.Users Nova_MOD_Users = new Nova_MOD.Users();
        Nova_BLL.Users Nova_BLL_Users = new Nova_BLL.Users();
        try
        {
            Nova_MOD_Users.vUserNo = txtUserNo.Text.ToString().Trim();
            Nova_MOD_Users.vPassWord = txtPassWord.Text.ToString().Trim();
            //Nova_MOD_Users.vPassWord = "test";

            i = Nova_BLL_Users.Exists(Nova_MOD_Users);

            if (i > 0)
            {
                //网页Cookies增加用户代码、仓库代码、名称、类型
                HttpCookie Cookies = new HttpCookie("vNovaUserNo", txtUserNo.Text.ToString().Trim());//网页Cookies增加用户代码
                Response.Cookies.Add(Cookies);

                //2012-03-06
                string strSQL = @"SELECT W.WareHsCode,W.WareHsName,W.WareHsType 
                                FROM dbo.tbUser U LEFT JOIN dbo.TB_WAREHS W ON W.WareHsCode=U.WID
                                WHERE u.vUserNo='" + txtUserNo.Text.ToString().Trim() + "'";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                ds = dbHelper.ExecuteDataSet(cmd);
                string strWCode = ds.Tables[0].Rows[0]["WareHsCode"].ToString();
                string strWName = ds.Tables[0].Rows[0]["WareHsName"].ToString();
                string strWareHsType = ds.Tables[0].Rows[0]["WareHsType"].ToString();

                HttpCookie WCode = new HttpCookie("WCode", strWCode);
                Response.Cookies.Add(WCode);

                HttpCookie WName = new HttpCookie("WName", HttpUtility.UrlEncode(strWName));
                Response.Cookies.Add(WName);

                HttpCookie WType = new HttpCookie("WType", strWareHsType);
                Response.Cookies.Add(WType);

                Response.Redirect("Main.aspx", false);
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

    protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
    {
        txtUserNo.Text = "";
        txtPassWord.Text = "";
    }
}
